/**
 * User: muxin4ever
 * Date: Oct, 31, 2012
 * Time: 21:25
 */

package gui;

import handler.FileHandler;
import handler.InputHandler;
import handler.OutputHandler;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;

import calculation.MatrixLibrary;

import common.MyLabel;

public class FrameMain extends JFrame {
	private PanelCalculationBar calcBar = new PanelCalculationBar(this);
	private PanelOrganizerBar orgBar = new PanelOrganizerBar(this);
	private PanelSetting settingBar = new PanelSetting(this);
	private PanelDisplayMatrix displayPanel = new PanelDisplayMatrix(this);
	private PanelDisplayMatrixList listPanel = new PanelDisplayMatrixList(this);

	//private DialogAddByHand addByHandDialog = new DialogAddByHand();
	private DialogAddByFile addByFileDialog = new DialogAddByFile(this);
	private DialogDeleteFile addDeleteFileDialog = new DialogDeleteFile(this);
	private DialogRenameFile addRenameFileDialog = new DialogRenameFile(this);
	private DialogNameResultMatrix nameResultMatrixDialog = new DialogNameResultMatrix(this);
	private DialogConfirmDone confirmDoneDialog = new DialogConfirmDone(this);
	private DialogConfirmError confirmErrorDialog = new DialogConfirmError(this);
	private DialogAddSubroutine subroutine = new DialogAddSubroutine(this);
	private MyLabel loadingLabel = new MyLabel(new ImageIcon(
			"./image/loading2.gif"));
	private MyLabel mainLabel = new MyLabel(new ImageIcon(
			"./image/frame.png"));

	private JLayeredPane layeredPane = new JLayeredPane();

	private MatrixLibrary matrixLibrary;
	private InputHandler inputHandler;
	private OutputHandler outputHandler;
	private FileHandler fileHandler;

	public FrameMain(MatrixLibrary matrixLibrary, InputHandler inputHandler,
			OutputHandler outputHandler,FileHandler fileHandler) {
		this.matrixLibrary = matrixLibrary;
		this.inputHandler = inputHandler;
		this.outputHandler = outputHandler;
		this.fileHandler = fileHandler;
		setSize(821, 600);
		setTitle("Matrix Calculator");
		setDefaultCloseOperation(this.EXIT_ON_CLOSE);
		setResizable(false);
		setVisible(true);

		calcBar.setBounds(0, 0, 300, 600);

		loadingLabel.setBounds(300, 150, 300, 300);
		mainLabel.setBounds(-5, -10, 821, 600);

		displayPanel.setBounds(300, 0, 521, 600);

		layeredPane.setBounds(0, 0, 821, 600);
		layeredPane.add(mainLabel, new Integer(0));
		layeredPane.add(loadingLabel, new Integer(1));

		this.add(layeredPane);

		mainLabel.add(calcBar);
		mainLabel.add(orgBar);
		mainLabel.add(settingBar);
		mainLabel.add(displayPanel);
		mainLabel.add(listPanel);

		calcBar.setVisible(true);
		orgBar.setVisible(false);
		settingBar.setVisible(false);
		displayPanel.setVisible(false);
		listPanel.setVisible(false);
	//	addByHandDialog.setVisible(false);
		addByFileDialog.setVisible(false);
		addDeleteFileDialog.setVisible(false);
		addRenameFileDialog.setVisible(false);
		nameResultMatrixDialog.setVisible(false);
		confirmDoneDialog.setVisible(false);
		loadingLabel.setVisible(false);

		String[] nameList = (String[]) matrixLibrary.getNameList().toArray(new String[0]);
		this.getPanelCalculationBar().setMatrixNameList(nameList);

	}

	public PanelCalculationBar getPanelCalculationBar() {
		return calcBar;
	}

	public PanelOrganizerBar getPanelOrganizerBar() {
		return orgBar;
	}

	public PanelSetting getPanelSetting() {
		return settingBar;
	}

	public PanelDisplayMatrix getPanelDisplayMatrix() {
		return displayPanel;
	}

	public PanelDisplayMatrixList getPanelDisplayMatrixList() {
		return listPanel;
	}

	public MyLabel getLoadingLabel() {
		return loadingLabel;
	}

	/*public JFrame getDialogAddByHand() {
		return addByHandDialog;
	} */

	public JFrame getDialogAddByFile() {
		return addByFileDialog;
	}
	public JFrame getDialogAddSubroutine(){
		return subroutine;
	}

	public JFrame getDialogDeleteFile() {
		return addDeleteFileDialog;
	}

	public JFrame getDialogRenameFile() {
		return addRenameFileDialog;
	}

	public JFrame getDialogNameResultMatrix() {
		return nameResultMatrixDialog;
	}

	public JFrame getDialogConfirmDone() {
		return confirmDoneDialog;
	}
	
	public InputHandler getInputHandler() {
		return inputHandler;
	}

	public OutputHandler getOutputHandler() {
		return outputHandler;
	}

	public FileHandler getFileHandler() {
		return fileHandler;
	}
	public DialogConfirmError getDialogConfirmError(){
		return confirmErrorDialog;
	}
}
